package com.yy.controller;

import com.yy.dto.SetmealDto;
import com.yy.entity.Setmeal;
import com.yy.service.SetmealService;
import com.yy.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * create by KongFuning on 2022/8/3
 */
@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    /*
    * 分页
    * */
    @GetMapping("/page")
    public R pageSetmeal(Integer page,Integer pageSize,String name){
        return setmealService.pageSetmeal(page, pageSize, name);
    }

    /*
    * 添加套餐
    * */
    @PostMapping
    public R saveSetmeal(@RequestBody SetmealDto setmealDto){
        return setmealService.saveSetmeal(setmealDto);
    }

    /*
    * 修改套餐 回显数据
    * */
    @GetMapping("/{setmealId}")
    public R toUpdateSetmeal(@PathVariable String setmealId){
        return setmealService.toUpdateSetmeal(setmealId);
    }

    /*
    * 修改套餐
    * */
    @PutMapping
    public R updateSetmeal(@RequestBody SetmealDto setmealDto){
        return setmealService.updateSetmeal(setmealDto);
    }

    /*
     * 停售  起售
     * */
    @PostMapping("/status/{status}")
    public R isSale(@PathVariable("status") Integer status, String ids){
        return setmealService.isSale(status,ids);
    }

    /*
    * 删除套餐
    * */
    @DeleteMapping
    public R deleteSetmeal(String ids){
        return setmealService.deleteSetmeal(ids);
    }

    /*
    * 获取套餐分类中具体套餐
    * */
    @GetMapping("/list")
    public R setmealDetail(Setmeal setmeal){
        return setmealService.setmealDetail(setmeal);
    }

    /*
    * 根据id查询套餐
    * */
    @GetMapping("/dish/{id}")
    public R getSetmealById(@PathVariable String id){
        return setmealService.getSetmealById(id);
    }
}
